console.time('test');

let count = 0;
for (let i = 0; i < 10; i++) {
    let worker = new Worker('./worker.js');
    // 给子线程传递值
    worker.postMessage(40);

    // 监听值worker给主线程传递的消息
    worker.onmessage = event => {
        console.log(event.data);
        count++;
        if (count === 10) {
            console.timeEnd('test');
        }
        worker.terminate(); // 关闭worker
    }
}